package com.zuohuaipan.headine.fragment;


import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.zuohuaipan.headine.R;
import com.zuohuaipan.headine.adapter.Menu_list_Adapter;
import com.zuohuaipan.headine.utils.Xutils_video_image;

public class Menu_Fragment extends Fragment {
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;
    private ListView lv;
    private ImageView menu_img;
    private TextView menu_name;


    public Menu_Fragment() {
        // Required empty public constructor
    }

    // TODO: Rename and change types and number of parameters
    public static Menu_Fragment newInstance(String param1, String param2) {
        Menu_Fragment fragment = new Menu_Fragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_menu_, container, false);
        //找到控件
        initView(view);


        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        //更新UI
        updateUI();
    }


    private void updateUI() {
        SharedPreferences spf = getActivity().getSharedPreferences("myheading", Context.MODE_PRIVATE);
        boolean b = spf.getBoolean("islogin", false);
        if (b) {
            String qqname = spf.getString("qqname", "111");
            String qqimg = spf.getString("qqimg", "");

            Xutils_video_image.display(menu_img, qqimg);
            menu_name.setText(qqname);
        }

    }

    private void initView(View view) {
        lv = (ListView) view.findViewById(R.id.menu_list);
        menu_img = (ImageView) view.findViewById(R.id.menu_img);
        menu_name = (TextView) view.findViewById(R.id.menu_name);
        lv.setAdapter(new Menu_list_Adapter(getActivity()));
    }

}
